package com.wfx.controller;


import com.wfx.entity.*;
import com.wfx.service.IWxbGoodsSpecService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2021-01-21
 */
@RestController
@RequestMapping("/spec")
@CrossOrigin
public class WxbGoodsSpecController {

    @Autowired
    private IWxbGoodsSpecService iWxbGoodsSpecService;

    //查询所有
    @PostMapping("findAll")
    public List<WxbGoodsSpec> findAll(){
        return iWxbGoodsSpecService.list();
    }

    @PostMapping("/findByName")
    @ApiOperation("根据名称查ID")
    public List<WxbGoodsSpec>  findByName(@RequestBody List<String> specList){
        return iWxbGoodsSpecService.select(specList);
    }
    //搜索分页加条件
    @PostMapping("/search")
    public PageResult<WxbGoodsSpec> search(@RequestBody PageDTO<WxbGoodsSpec> pageDTO) {
        //System.out.println(pageDTO);
        if (pageDTO==null){
            pageDTO = new PageDTO<>(1,5,null);
        }
        PageResult search = iWxbGoodsSpecService.search(pageDTO);
        System.out.println(search);
        return search;
    }
    //批量删除
    @RequestMapping("/del")
    public Result del(@RequestBody List<WxbGoodsSpec> data) {
        //System.out.println(1);
        Result del = iWxbGoodsSpecService.del(data);
        return del;
    }

    //修改

    @RequestMapping("/save")
    public Result save(@RequestBody WxbGoodsSpec wxbGoodsSpec){
        System.out.println(wxbGoodsSpec);
        Result result = iWxbGoodsSpecService.saveSpec(wxbGoodsSpec);
        return result;
    }


    //添加
    @RequestMapping("/update")
    public Result up(@RequestBody WxbGoodsSpec wxbGoodsSpec){
        System.out.println(wxbGoodsSpec);
        Result result = iWxbGoodsSpecService.up(wxbGoodsSpec);
        return result;
    }
}
